package com.training.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.BaseFragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.training.activity.AboutUsActivity;
import com.training.activity.FeedbackActivity;
import com.training.activity.MyCollectActivity;
import com.training.bean.User;
import com.training.databinding.FragmentHomeBinding;
import com.training.databinding.FragmentMineBinding;

public class MineFragment extends BaseFragment<FragmentMineBinding> {
    private User user;

    @Override
    public FragmentMineBinding binding() {
        return FragmentMineBinding.inflate(getLayoutInflater());
    }

    @Override
    public void onCreated(Bundle savedInstanceState) {
        mBinding.myCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyCollectActivity.class);
                startActivity(intent);
            }
        });
        mBinding.aboutUs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AboutUsActivity.class);
                startActivity(intent);
            }
        });
        mBinding.feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, FeedbackActivity.class);
                startActivity(intent);
            }
        });
        loadData();
        refreshUI();
    }

    @Override
    public void loadData() {
        user = dc.getUser();
    }

    @Override
    public void refreshUI() {
        // 加载圆角图片
        Glide.with(context)
                .load(user.avatar)
                .circleCrop()  // 16dp 圆角
                .into(mBinding.avatar);
        mBinding.username.setText(user.nickname);
    }
}
